package logic

import (
	"context"
	"taobao-merchandise/models/mysql"

	"taobao-merchandise/userrpc/internal/svc"
	"taobao-merchandise/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 收藏添加
func (l *CommentAddLogic) CommentAdd(in *userrpc.CommentAddRequest) (*userrpc.CommentAddResponse, error) {
	// todo: add your logic here and delete this line

	comment := &mysql.Comment{
		UserId:  in.UserId,
		GoodsId: in.GoodsId,
	}
	err := comment.CommentAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &userrpc.CommentAddResponse{
		CommentId: int64(comment.ID),
	}, nil
}
